package com.mapreduce;

import java.io.IOException;

import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;
//在hadoop中，普通的java类不适合做网络序列化传输，hadoop对java的类型进行了封装，以便于利用hadoop的序列化框架进行序列化传输
public class WordCountMapper extends Mapper<LongWritable,Text,Text,LongWritable>{

	/**
	 * map方法是每读一行调用一次
	 */
	@Override
	protected void map(LongWritable key, Text value,Context context)
			throws IOException, InterruptedException {
		//拿到一行内容，转成String类型
		String line = value.toString();
		//切分出一行中所有的单词
		String[] words = line.split(" ");
		//输出KV对
		for(String word:words){
			context.write(new Text(word), new LongWritable(1));
		}
	}
}
